/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			prefs.h
  \date			Aug 2012
  \author		TNick

  \brief		Contains the definition for Prefs class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PREFS_INC__
#define __PREFS_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<cpg/cpg.h>
#include	<prefbase.h>
#include	<memtrack.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */


/**
*	@brief	The singleton handles application preferences
*
*	@todo Think abolut what happens with storage when a new version is shipped
*	and installed on top of previous version. Some / all settings should be
*	imported.
*/
class Prefs		: public BBlocks::PrefBase, public MemTrack		{
	BBM_TRACK( Prefs );

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

public:

	/* the file is auto-generated by the prefs.py script */
#	include	"prefs_id.h"

private:


	/**
	*	@brief	number of elements in arrays
	*/
	enum		Cnt		{
		COUNT_STRINGS = INTERNAL__LAST_STRING - INTERNAL__FIRST_STRING + 1,
		COUNT_INTS = INTERNAL__LAST_INTEGER - INTERNAL__FIRST_INTEGER + 1,
		COUNT_REALS = INTERNAL__LAST_REAL - INTERNAL__FIRST_REAL + 1
	};


	/**
	*	@brief	indices in the arrays that cummulate all settings
	*/
	enum		StartLoc		{
		START_STRINGS = 0,
		START_INTS = START_STRINGS + COUNT_STRINGS ,
		START_REALS = START_INTS + COUNT_INTS,
		START_NEXT = START_REALS + COUNT_REALS
	};



	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:


	QString				stgs_s_[COUNT_STRINGS];
	qint64				stgs_i_[COUNT_INTS];
	qreal				stgs_r_[COUNT_REALS];





	/**
	*	@brief	array of names for each preference
	*/
	static const char *			pref_names_[];


	/**
	*	@brief	the one and only instance
	*/
	static Prefs *				uniq_;


	/**
	*	@brief	array of string settings
	*/
	static const char *			defaults_s_[COUNT_STRINGS];


	/**
	*	@brief	array of integer settings
	*/
	static qint64				defaults_i_[COUNT_INTS];


	/**
	*	@brief	array of integer settings
	*/
	static qreal				defaults_r_[COUNT_REALS];


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

private:


	/**
	*	@brief	constructor;
	*/
	Prefs					( void );


	/**
	*	@brief	destructor;
	*/
	~Prefs					( void );


public:


	/**
	*	@brief	initialisation method for printing system
	*/
	static bool				init					( void );


	/**
	*	@brief	termination method for printing system
	*/
	static void				end						( void );


	/**
	*	@brief	the one and only instance
	*/
	static inline Prefs *	unique					( void )
	{ return uniq_; }


	/**
	*	@brief	convert a real number to a string according to current preferences
	*/
	static QString			toString				( qreal val );




	/* ******************************************************************* */
	/** @name 	Retrieving settings                                        */
	/* ******************************************************************* */
	///@{


public:


	/**
	*	@brief	get a string setting
	*/
	static inline void			get				(
			Id				pref_id,
			QString &		out
			)
	{ uniq_->PrefBase::get( pref_id, out ); }


	/**
	*	@brief	get an integer setting
	*/
	static inline void			get				(
			Id				pref_id,
			qint64 &		out
			)
	{ uniq_->PrefBase::get( pref_id, out ); }


	/**
	*	@brief	get a color setting
	*/
	static inline void			get				(
			Id				pref_id,
			QColor &		out
			)
	{ uniq_->PrefBase::get( pref_id, out ); }


	/**
	*	@brief	get a real setting
	*/
	static inline void			get				(
			Id				pref_id,
			qreal &			out
			)
	{ uniq_->PrefBase::get( pref_id, out ); }


	/**
	*	@brief	get a string setting
	*/
	static inline QString		getS				(
			Id				pref_id
			)
	{ return uniq_->PrefBase::getS( pref_id ); }



	/**
	*	@brief	get an integer setting
	*/
	static inline qint64		getI		(
			Id				pref_id
			)
	{ return uniq_->PrefBase::getI( pref_id ); }


	/**
	*	@brief	get a color setting
	*/
	static inline QColor		getColor		(
			Id				pref_id
			)
	{ return uniq_->PrefBase::getColor( pref_id ); }


	/**
	*	@brief	get a real setting
	*/
	static inline qreal			getR		(
			Id				pref_id
			)
	{ return uniq_->PrefBase::getR( pref_id ); }


	///@}
	/* ******************************************************************* */




	/* ******************************************************************* */
	/** @name 	Saving settings                                            */
	/* ******************************************************************* */
	///@{


public:


	/**
	*	@brief	set a string setting
	*/
	static inline void				set				(
			Id				pref_id,
			const QString &	inp
			)
	{ uniq_->PrefBase::set( pref_id, inp ); }


	/**
	*	@brief	set an integer setting
	*/
	static inline void				set				(
			Id					pref_id,
			const qint64 &		inp
			)
	{ uniq_->PrefBase::set( pref_id, inp ); }


	/**
	*	@brief	set a color setting
	*/
	static inline void				set				(
			Id					pref_id,
			const QColor &		inp
			)
	{ uniq_->PrefBase::set( pref_id, inp ); }


	/**
	*	@brief	set an integer setting
	*/
	static inline void				set				(
			Id					pref_id,
			const  qreal &		inp
			)
	{ uniq_->PrefBase::set( pref_id, inp ); }


	///@}
	/* ******************************************************************* */



	/* ******************************************************************* */
	/** @name 	Support for interactive change of a setting                */
	/* ******************************************************************* */
	///@{


public:


	/**
	*	@brief	Presents the name and value of one preference
	*/
	static inline void				interactiveGet			(
			const QString &					s_name,
			BBlocks::UserMsg &				um
			)
	{ uniq_->PrefBase::interactiveGet( s_name, um ); }


	/**
	*	@brief	Sets a preference to its default value
	*/
	static inline void				interactiveReset		(
			const QString &					s_name,
			BBlocks::UserMsg &				um
			)
	{ uniq_->PrefBase::interactiveReset( s_name, um ); }


	/**
	*	@brief	Changes the name of one preference
	*/
	static inline void				interactiveSet			(
			const QString &					s_name,
			const QString &					s_val,
			BBlocks::UserMsg &				um
			)
	{ uniq_->PrefBase::interactiveSet( s_name, s_val, um ); }


	///@}
	/* ******************************************************************* */


public:


	/**
	*	@brief	get the index of the preference given its name or ID_INVALID if not found
	*/
	static Id				byName					( const QString & s_name );


	/**
	*	@brief	presents all preferences or all that match specified pattern
	*/
	static inline void		dump					(
			const QString &					s_pattern,
			BBlocks::UserMsg &				um
			)
	{ uniq_->PrefBase::dump( s_pattern, um ); }




	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class Prefs	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __PREFS_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
